<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">

                    <input type="hidden" id="parentPhone" name="params[parentPhone]" th:value="${phone}"/>
                    <input type="hidden" id="agentId" name="params[agentId]" th:value="${agentId}"/>

                    <ul>
                        <li>商户编号：<input type="text" name="params[merchantNo]"/>
                        </li>

                        <li>商户名称：<input type="text" name="params[merchantCnName]"/>
                        </li>
                        <li>手机号码：<input type="text" name="params[phone]"/>
                        </li>

                        <li>
                            用户等级：<select name="params[levle]" th:with="type=${@dict.getType('sys_merchant_level')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            认证状态：<select name="params[realNameStatus]"
                                         th:with="type=${@dict.getType('sys_freeze_status')}">
                            <option value="">所有</option>
                            <option value="10B">已认证</option>
                            <option value="10A">未认证</option>
                            <option value="10C">实名失败</option>
                        </select>
                        <li class="select-time"><label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text"   class="time-input" id="endTime"  placeholder="结束时间"  name="params[endTime]"/>
                        </li>
                        </li>
                        <li><a class="btn btn-primary btn-rounded btn-sm"
                               onclick="search1()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm"
                               onclick="reset('formId')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>

                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()">
                <i class="fa fa-download">导出</i>
            </a>

        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>

</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    function search1() {
        $.table.search("formId");
    }
    //重置form
    function reset(formId) {
        var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
        $("#" + currentId)[0].reset();
    }

    var listFlag = [[${@permission.hasPermi('system:dict:list')}]];
    var prefix = ctx + "system/merchant";
    var datas = [[${@dict.getType('sys_merchant_level')}]];//商户等级
    var datas1 = [[${@dict.getType('sys_freeze_status')}]];//商户实名认证状态

    $(function () {
        var options = {
            url: prefix + "/customerRelationList",
            updateUrl: prefix + "/edit/{id}",
            exportUrl: prefix + "/export",
            updateRoleUrl: prefix + "/editRole/{id}", //修改权限
            updateQuotaUrl: prefix + "/editQuota/{id}",//修改限额
            modalName: "商户",
            sortName: " createTime",
            sortOrder: "desc",
            queryParams: queryParams,
            search: false,
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'merchantNo',
                    title: '商户编号',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return '<a href="#" onclick="detail(\'' + row.id + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'merchantCnName',
                    title: '商户名称',
                    sortable: true
                },

                {
                    field: 'parentMerchantName',
                    title: '上级姓名',
                },
                {
                    field: 'parentMerchantPhone',
                    title: '上级联系电话',
                },
                {
                    field: 'level',
                    title: '商户等级',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'phone',
                    title: '手机号',
                    sortable: true
                },
                {
                    field: 'idCardNumber',
                    title: '身份证号',
                    sortable: true
                },
                {
                    field: 'bankAccount',
                    title: '银行卡号',
                    sortable: true
                },
                {
                    field: 'realNameStatus',
                    title: '实名状态',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas1, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    align: 'center',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                            actions.push('<a class="btn btn-info btn-xs  " href="#" onclick="customerRelation(\'' + row.phone + '\')"><i class="fa fa-list-ul"></i>客户关系</a> ');
                        //actions.push(statusTools(row));
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function queryParams(params) {
        return {
            "parentPhone": $("#parentPhone").val(),
            "params[beginTime]": $("#beginTime").val(),
            "params[endTime]": $("#endTime").val(),
            pageSize: params.limit,
            pageNum: params.offset / params.limit + 1,
            searchValue: params.search,
            orderByColumn: params.sort,
            isAsc: params.order
        };
    }


    //详情	detailUrl: prefix + "//{id}",
    function detail(id) {
        var url = prefix + '/detail/' + id;
        createMenuItem(url, "查看详情");
    }

    //使用状态
    function statusTools(row) {
        var content = ""
        if (row.useStatus == "10A") {
            content += '<a class="btn btn-danger btn-xs' + removeFlag + '" href="#" onclick="prohibit(\'' + row.id + '\')")" ><i class="fa fa-remove"></i>禁用</a> ';
        } else {
            content += '<a class="btn btn-info btn-xs" href="#" onclick="enable(\'' + row.id + '\')"><i class="fa fa-play"></i>启用</a> ';
        }
        return content;
    }


    /*启用*/
    function prohibit(id) {
        $.modal.confirm("确认要启用该商户吗？", function () {
            $.operate.post(prefix + "/updateUseStatusById", {"id": id});
        })
    }

    //禁用
    function enable(id) {
        $.modal.confirm("确认要禁用该商户吗？", function () {
            $.operate.post(prefix + "/updateUseStatusById", {"id": id});
        })
    }

    //客户关系
    function customerRelation(phone) {
        var url = prefix + '/customerRelation/' + phone;
        createMenuItem(url, "客户关系");
    }

</script>
</body>
</html>